<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ez="http://java.sun.com/jsf/composite/ezcomp"
      >
    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            #{bundle.ListAdv}
        </ui:define>
        <ui:define name="menuitem">ListAdv.xhtml</ui:define>
        <ui:define name="body">
            <ui:include src="/sections/advsShowDialog.xhtml" />
            <table>
                <tr>
                    <td>
                        <ui:include src="/sections/map.xhtml" />
                    </td><td class="mapright">
                        <h:outputScript name="advs.js"/>   

                        <h:form id="criteria" prependId="false">
                            <p:panel>
                                <p:panel>
                                    <table width="100%">
                                        <tr id="rooms">
                                            <td width="20%">
                                                <h:outputLabel value="#{bundle.RoomsCount}" />
                                            </td>
                                            <td width="40%">
                                                <p:selectOneMenu id="RoomsSelector" value="#{advertQueryController.advertQuery.room_count}" styleClass="label_width" >  
                                                    <f:selectItem itemLabel="#{bundle.All}" itemValue="0" />  
                                                    <f:selectItem itemLabel="#{bundle.Rooms0}" itemValue="-1" />  
                                                    <f:selectItem itemLabel="#{bundle.Rooms1}" itemValue="1" />  
                                                    <f:selectItem itemLabel="#{bundle.Rooms2}" itemValue="2" />  
                                                    <f:selectItem itemLabel="#{bundle.Rooms3}" itemValue="3" /> 
                                                    <f:selectItem itemLabel="#{bundle.Rooms4plus}" itemValue="3" /> 
                                                </p:selectOneMenu>
                                            </td><td width="40%">

                                            </td>
                                        </tr>
                                        <tr id="totalarea">
                                            <td width="20%">
                                                <h:outputLabel value="#{bundle.TotalSqure}" />
                                            </td>
                                            <td width="40%">
                                                <h:outputLabel value="#{bundle.from}" />                                        
                                                <p:inputText id="TotalAreaMin" value="#{advertQueryController.advertQuery.total_sqrmin}"  size="3"/>  
                                            </td><td width="40%">
                                                <h:outputLabel value=" #{bundle.to} " />
                                                <p:inputText id="TotalAreaMax" value="#{advertQueryController.advertQuery.total_sqrmax}" size="3"/>  
                                                <h:outputLabel value=" m" /><sup>2</sup>
                                            </td>
                                        </tr>
                                        <tr id="price">
                                            <td width="20%">
                                                <h:outputLabel value="#{bundle.Price}" />
                                            </td>
                                            <td width="40%">
                                                <h:outputLabel value="#{bundle.from} " />                                        
                                                <p:inputText id="PriceRangeMin" value="#{advertQueryController.advertQuery.pricemin}"  size="2"/>  
                                                <h:outputLabel value="'000$"/>
                                            </td><td width="40%">
                                                <h:outputLabel value="#{bundle.to} " />
                                                <p:inputText id="PriceRangeMax" value="#{advertQueryController.advertQuery.pricemax}" size="2"/>  
                                                <h:outputLabel value="'000$" />
                                            </td>
                                        </tr>
                                        <tr id="flors">
                                            <td width="20%">
                                                <h:outputLabel value="#{bundle.Floor}" />
                                            </td>
                                            <td width="40%">
                                                <h:outputLabel value="#{bundle.from} " />
                                                <p:inputText id="FlorRangeMin" value="#{advertQueryController.advertQuery.floormin}"  size="2"/>  
                                            </td><td width="40%">
                                                <h:outputLabel value="#{bundle.to} " />
                                                <p:inputText id="FlorRangeMax" value="#{advertQueryController.advertQuery.floormax}" size="2"/>  
                                            </td>
                                        </tr>
                                        <tr id="florfirst">
                                            <td width="20%">
                                                <h:outputLabel value="" />
                                            </td>
                                            <td width="40%">
                                                <h:outputLabel value="#{bundle.first} " />
                                                <p:selectBooleanCheckbox id="FlorFirst" value="#{advertQueryController.advertQuery.floorfirst}" style="display: inline-block"/>  
                                            </td><td width="40%">
                                                <h:outputLabel value="#{bundle.last}  " />
                                                <p:selectBooleanCheckbox id="FlorLast" value="#{advertQueryController.advertQuery.floorlast}" style="display: inline-block" />  
                                            </td>
                                        </tr>
                                    </table>
                                </p:panel>   
                                <div class="hide">
                                    <h:inputText id="zoom" value="#{advertQueryController.advertQuery.zoom}"/>
                                    <h:inputText id="lats" value="#{advertQueryController.advertQuery.lats}"/>
                                    <h:inputText id="latn" value="#{advertQueryController.advertQuery.latn}"/>
                                    <h:inputText id="lngw" value="#{advertQueryController.advertQuery.lngw}"/>
                                    <h:inputText id="lnge" value="#{advertQueryController.advertQuery.lnge}"/>
                                </div>

                                <p:panel>
                                    <p:commandButton id="search" onclick="getCurrentBounds('')"  value="#{bundle.LookUp}"  action="#{advertController.listAdvertsInBounds()}" update=":advs"  />
                                    <p:commandButton id="save" onclick="getCurrentBounds('')" value="#{bundle.Save}" action="#{advertQueryController.advertQuerySave()}" update=":criteria"
                                                     rendered="#{advertQueryController.fc.user.id!=null}"/>
                                    <p:commandButton id="new" onclick="getCurrentBounds('')" value="#{bundle.New}" action="#{advertQueryController.advertQueryClear()}" update=":criteria"
                                                     rendered="#{advertQueryController.fc.user.id!=null}"/>
                                </p:panel>
                            </p:panel>
                            <div class="advsquery_scroll" styleClass="advsqueryscroll"> 
                                <p:dataTable id="advsquery" value="#{advertQueryController.advertQueryList}" var="advq" 
                                             rendered="#{advertQueryController.fc.user.id!=null and advertQueryController.advertQueryList.size()>0}">
                                    <p:column>
                                        <p:commandLink  onclick="getCurrentBounds('')" action="#{advertQueryController.pushAdvertQuery(advq)}" update=":criteria" oncomplete="setMapBounds('')">
                                            <h:outputText value="#{bundle.rc0}" rendered="#{advq.room_count==-1}"/>
                                            <h:outputText value="#{bundle.rc1}" rendered="#{advq.room_count==1}"/>
                                            <h:outputText value="#{bundle.rc2}" rendered="#{advq.room_count==2}"/>
                                            <h:outputText value="#{bundle.rc3}" rendered="#{advq.room_count==3}"/>
                                            <h:outputText value="#{bundle.rc4}" rendered="#{advq.room_count==4}"/>
                                            <h:outputText value=" #{advq.pricemin}-#{advq.pricemax}k$ "/>
                                            <h:outputText value="#{advq.total_sqrmin}-#{advq.total_sqrmax}m2 "/>
                                            <h:outputText value="#{advq.floormin}-#{advq.floormax} "/>
                                            <h:outputText value="#{advq.floorfirst?bundle.first:''}  #{advq.floorlast?bundle.last:''} "/>
                                        </p:commandLink>   
                                    </p:column>                            
                                    <p:column>
                                        <p:commandButton id="del#{advq.number}" image="ui-icon-cancel" onclick="getCurrentBounds('')" action="#{advertQueryController.advertQueryRemove(advq.id)}" update=":criteria"/>
                                        <h:inputHidden id="id#{advq.number}" value="#{advq.id}"/>
                                        <h:inputHidden id="lats#{advq.number}" value="#{advq.lats}"/>
                                        <h:inputHidden id="lnge#{advq.number}" value="#{advq.lnge}"/>
                                        <h:inputHidden id="latn#{advq.number}" value="#{advq.latn}"/>
                                        <h:inputHidden id="lngw#{advq.number}" value="#{advq.lngw}"/>
                                    </p:column>
                                </p:dataTable>
                            </div>
                        </h:form>
                    </td></tr></table>

            <h:form id="advs" prependId="false" target="_blank">

                <div   class="advs_scroll" >
                    <p:ajaxStatus oncomplete="parseTable()"/>
                    <p:remoteCommand name="loadAdvert" update=":advshow" oncomplete="asd.show()"/>
                    <p:dataTable id="advslist" value="#{advertController.adverts}" var="adv" 
                                 paginator="true" rows="20"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="10,20,50, 100"
                                 rendered="#{advertController.adverts.size()>0}"
                                 > 
                        <f:facet name="header">  
                            #{bundle.ListAdvTable}
                        </f:facet> 
                        <p:column><f:facet name="header">#</f:facet>
                            <p:commandLink oncomplete="setMapCenter(#{adv.item.lat},#{adv.item.lng})">
                                <f:setPropertyActionListener value="#{adv.item}" target="#{advertController.newAdvert}"/>
                                <h:graphicImage url="/resources/images/markers/#{adv.printIconName(adv)}" />
                            </p:commandLink>
                            <h:inputHidden id="lat#{adv.number}" value="#{adv.item.lat}" />
                            <h:inputHidden id="lng#{adv.number}" value="#{adv.item.lng}" />
                        </p:column>
                        <p:column >
                            <f:facet name="header">#{bundle.Address}</f:facet>
                            <ez:advertView item="#{adv.item}"/>
                        </p:column>
                        <p:column><f:facet name="header">#{bundle.Notes}</f:facet> 
                            <p:panel style="width:300px">
                                <h:outputText value="#{adv.item.notes}" />
                            </p:panel>    
                        </p:column>
                        <p:column>
                            <div style="display: inline-block;vertical-align: top">
                                <p:commandButton image="ui-icon-search"
                                                 update=":advshow"
                                                 action="#{advertController.recordAdvertToUserHistoty(adv.item.id)}"
                                                 oncomplete="asd.show()">
                                    <f:setPropertyActionListener value="#{adv.item}" target="#{advertController.newAdvert}" /> 
                                </p:commandButton>
                                
                                <a href="ShowAdv.xhtml?advid=#{adv.item.id}" target="_blank" class="fg-button ui-state-default ui-corner-all">
                                    <span class="ui-icon ui-icon-newwin"></span></a>
                                <p:commandButton rendered="#{!advertController.inUserCart(adv.item.id)}" image="ui-icon-cart"
                                                 update=":advs"
                                                 action="#{advertController.recordAdvertToUserCart(adv.item.id)}"
                                                 oncomplete="">
                                    <f:setPropertyActionListener value="#{adv.item}" target="#{advertController.newAdvert}" /> 
                                </p:commandButton>
                                <p:commandButton rendered="#{advertController.inUserCart(adv.item.id)}" image="ui-icon-close" styleClass="ui-icon-closethick"
                                                 update=":advs"
                                                 action="#{advertController.removeAdvertFromUserCart(adv.item.id)}"
                                                 oncomplete="">
                                    <f:setPropertyActionListener value="#{adv.item}" target="#{advertController.newAdvert}" /> 
                                </p:commandButton>
                            </div>    
                        </p:column>
                    </p:dataTable>
                </div>
            </h:form>   
        </ui:define>
    </ui:composition>
</html>